#ifndef CTC_H_
#define CTC_H_

#include "typedefs.h"
#include "bsp.h"
#include "mrfi.h"
#include "nwk_types.h"
#include "nwk_api.h"
#include "nwk.h"
#include "LCD.h"
#include "Menu.h"

#define DEFAULT_RCR_SLEEP_TIME (5)
#define DEFAULT_RTS_SLEEP_TIME (3)
#define NUM_RTSS (16)
#define NUM_RCRS (16)
#define ONE_SECOND_PERIOD (32768)
#define ACKNOWLEDGE (0xAA)
#define ACK_MESSAGE_LENGTH (3)
#define CLOSED (0)
#define OPEN (1)
#define ON (1)
#define OFF (0)
#define NO_DEVICE_FOUND (0xFF)
#define RCR_IDENT (0)
#define RTS_IDENT (1)
#define RCR_REQ (2)
#define RTS_REQ (3)
#define KEEP_FRAME (0)
#define DISCARD_FRAME (1)
#define K_P (1)
#define K_D (.1)
#define K_I (.01)
#define HVAC_THRESHOLD (3)
#define DECISION_PERIOD (10)

RCR_t* createNewRCR(linkID_t, zone_t, sleepTime_t, battLife_t);
RTS_t* createNewRTS(linkID_t, zone_t, sleepTime_t, battLife_t);

void deleteRCR(RCR_t**, uint8_t);
void deleteRTS(RTS_t**, uint8_t);

void addNewRCR(RCR_t**, RCR_t*);
void addNewRTS(RTS_t**, RTS_t*);

uint8_t isRCR(RCR_t**, linkID_t);
uint8_t isRTS(RTS_t**, linkID_t);

uint8_t findRTSbyLinkID(RTS_t**, linkID_t);
uint8_t findRCRbyLinkID(RCR_t**, linkID_t);

uint8_t findRCRbyZone(RCR_t**, zone_t);
uint8_t findRTSbyZone(RTS_t**, zone_t);

void updateRCR(RCR_t**, linkID_t, battLife_t);
void updateRTS(RTS_t**, linkID_t, temp_t, battLife_t);

void ackRCR(RCR_t**, linkID_t);
void ackRTS(RTS_t**, linkID_t);

error_t calculateError(RTS_t**, uint8_t, temp_t);
error_t sumErrors(RTS_t**, temp_t);

void sortZones(RTS_t** RTSarray, uint8_t* sortedIndices);

void openRCR(RCR_t**, zone_t);
void closeRCR(RCR_t**, zone_t);

#endif /*CTC_H_*/
